import 'package:flutter/material.dart';

class AnimatedBuildDemo extends StatefulWidget {
  @override
  _AnimatedBuildDemoState createState() => _AnimatedBuildDemoState();
}

class _AnimatedBuildDemoState extends State<AnimatedBuildDemo>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: Duration(seconds: 14),
      vsync: this,
    )..forward();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final Animation stopsAnimation = Tween(begin: 0.0, end: 1.0)
        .chain(CurveTween(curve: Interval(0.0, 0.2)))
        .animate(_controller);
    final Animation stopsAnimation2 = Tween(begin: 1.0, end: 0.0)
        .chain(CurveTween(curve: Interval(0.4, 0.95)))
        .animate(_controller);

    return Scaffold(
      appBar: AppBar(title: Text('AnimatedBuildDemo')),
      body: Center(
        child: AnimatedBuilder(
          animation: _controller,
          builder: (BuildContext context, Widget child) {
            return Container(
              width: 300,
              height: 300,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                color: Colors.blue,
                gradient: RadialGradient(
                  colors: [Colors.blue[600], Colors.blue[100]],
                  stops: _controller.value <= 0.2
                      ? [stopsAnimation.value, stopsAnimation.value + 0.1]
                      : [stopsAnimation2.value, stopsAnimation2.value + 0.1],
                ),
              ),
            );
          },
        ),
      ),
    );
  }
}
